package com.wyzz.hr.action;

import java.util.*;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.base.DWRUtil;
import com.wyzz.hr.bo.ILeavecalendarBO;
import com.wyzz.hr.pojo.Leavecalendar;
import com.wyzz.hr.pojo.Location;

public class LeavecalendarManageAction extends BaseAction {
	class LCType {
		int lcSign;
		String signName;

		public LCType(int lc, String sN) {
			this.lcSign = lc;
			this.signName = sN;
		}

		public int getLcSign() {
			return this.lcSign;
		}

		public void setLcSign(int lcSign) {
			this.lcSign = lcSign;
		}

		public String getSignName() {
			return this.signName;
		}

		public void setSignName(String signName) {
			this.signName = signName;
		}
	}

	public LeavecalendarManageAction() {
	}

	public String execute() throws Exception {
		locationList = getDrillDown("Location", new String[] { "1" });
		Location templ = new Location();
		templ.setId("all");
		templ.setLocationName("\u5168\u90E8\u5730\u533A");
		locationList.add(0, templ);
		typeList = new ArrayList();
		typeList.add(new LCType(0, getTypeDescription(0)));
		typeList.add(new LCType(1, getTypeDescription(1)));
		typeList.add(new LCType(2, getTypeDescription(2)));
		if (yearSelect == 0)
			yearSelect = Calendar.getInstance().get(1);
		lc_BO = (ILeavecalendarBO) getBean("leavecalendarBO");
		result = lc_BO.getCalendarByYear(yearSelect);
		if (getInfoMeg() != null && getInfoMeg().length() > 0) {
			addSuccessInfo(getInfoMeg());
			setInfoMeg(null);
		}
		if (getErrorMsg() != null && getErrorMsg().length() > 0) {
			addErrorInfo(getErrorMsg());
			setErrorMsg(null);
		}
		return "success";
	}

	public String getTypeDescription(int lc_sign) {
		if (lc_sign == 0)
			return "\u516C\u4F11\u65E5";
		if (lc_sign == 1)
			return "\u5DE5\u4F5C\u65E5";
		if (lc_sign == 2)
			return "\u8282\u5047\u65E5";
		else
			return "Error";
	}

	public String getLocationName(Location lc_location) {
		if (lc_location == null)
			return "\u5168\u90E8\u5730\u533A";
		else
			return lc_location.getLocationName();
	}

	public String checkLeavecalendar(Leavecalendar lc) {
		if (lc == null)
			return "No input";
		if (lc.getLcDate() == null)
			return "\u6CA1\u6709\u65F6\u95F4\u8F93\u5165";
		if (lc.getLcDateDesc() != null && lc.getLcDateDesc().length() > 64)
			return "\u5907\u6CE8\u8D85\u8FC764\u5B57\u8282\u957F\u5EA6";
		if (lc.getLcLocationNo().getId().equals("all"))
			lc.setLcLocationNo(null);
		return null;
	}

	public String insertLeavecalendar(Leavecalendar lc) {
		if (!DWRUtil.checkAuth("leavecalendarManage", "execute").equals("HR"))
			return "\u60A8\u65E0\u6743\u6267\u884C\u6B64\u64CD\u4F5C\uFF0C\u8BF7\u91CD\u65B0\u767B\u9646\uFF01";
		String check = checkLeavecalendar(lc);
		if (check != null)
			return check;
		lc_BO = (ILeavecalendarBO) getBean("leavecalendarBO");
		List result = lc_BO.insertLeavecalendar(lc);
		if (result == null || result.size() == 0)
			return "suc";
		else
			return (String) result.get(0);
	}

	public String delLeavecalendar(String lcId) {
		if (!DWRUtil.checkAuth("leavecalendarManage", "execute").equals("HR"))
			return "\u60A8\u65E0\u6743\u6267\u884C\u6B64\u64CD\u4F5C\uFF0C\u8BF7\u91CD\u65B0\u767B\u9646\uFF01";
		lc_BO = (ILeavecalendarBO) getBean("leavecalendarBO");
		List result = lc_BO.deleteLeavecalendar(lcId);
		if (result == null || result.size() == 0)
			return "suc";
		else
			return (String) result.get(0);
	}

	public String updateLeavecalendar(Leavecalendar lc) {
		if (!DWRUtil.checkAuth("leavecalendarManage", "execute").equals("HR"))
			return "\u60A8\u65E0\u6743\u6267\u884C\u6B64\u64CD\u4F5C\uFF0C\u8BF7\u91CD\u65B0\u767B\u9646\uFF01";
		String check = checkLeavecalendar(lc);
		if (check != null)
			return check;
		lc_BO = (ILeavecalendarBO) getBean("leavecalendarBO");
		List result = lc_BO.updateLeavecalendar(lc);
		if (result == null || result.size() == 0)
			return "suc";
		else
			return (String) result.get(0);
	}

	public Leavecalendar loadLeavecalendar(String lcId) {
		if (!DWRUtil.checkAuth("leavecalendarManage", "execute").equals("HR")) {
			return null;
		} else {
			lc_BO = (ILeavecalendarBO) getBean("leavecalendarBO");
			return lc_BO.loadLeavecalendar(lcId);
		}
	}

	public int getYearSelect() {
		return yearSelect;
	}

	public void setYearSelect(int yearSelect) {
		this.yearSelect = yearSelect;
	}

	public ILeavecalendarBO getLc_BO() {
		return lc_BO;
	}

	public void setLc_BO(ILeavecalendarBO lc_BO) {
		this.lc_BO = lc_BO;
	}

	public List getLocationList() {
		return locationList;
	}

	public void setLocationList(List locationList) {
		this.locationList = locationList;
	}

	public List getResult() {
		return result;
	}

	public void setResult(List result) {
		this.result = result;
	}

	public List getTypeList() {
		return typeList;
	}

	public void setTypeList(List typeList) {
		this.typeList = typeList;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public String getInfoMeg() {
		return infoMeg;
	}

	public void setInfoMeg(String infoMeg) {
		this.infoMeg = infoMeg;
	}

	private static final long serialVersionUID = 1L;
	private int yearSelect;
	private List locationList;
	private List typeList;
	private List result;
	private String infoMeg;
	private String errorMsg;
	private ILeavecalendarBO lc_BO;
}
